// languagecomponents.h: interface for the signal class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_LANGUAGECOMPONENTS_H__A5613CDC_A001_4D02_8BA2_EFE6D50C0AFD__INCLUDED_)
#define AFX_LANGUAGECOMPONENTS_H__A5613CDC_A001_4D02_8BA2_EFE6D50C0AFD__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxtempl.h>
//These are 2 files from compressor source .
//It used to format some variables.
#include "compressor\block.h"
#include "compressor\from_file.h"
#include "graphdata.h"
#include "HelperStructures.h"
#include <vector>

const CString	DEFAULT_GROUP_NAME = "TIMING";
const CString	DEFAULT_FRAME_NAME = "1";
const CString	DEFAULT_GROUP_COMMENT = "timing";

//#define SPACEREPLACEMENT	210
// maximum groups in one script (There may be as many scripts in one document as you wish)
#define MAXIMUM_GROUPS		1000
//Maximum group sequences in complex group
#define	MAXIMUM_INGROUP		100


//Global functions
__int64 IntervalCompare( __int64 ComparingValue, __int64 Minimum, __int64 Maximum );
__int64 CStringToLong ( CString String );
CString Long64ToCString ( __int64 value );
CString GetFileExtension( CString Path );

//Exception classes
class WrongFileExtensionException{};
class WrongTypeOfWavesignal{};
class WrongSignalNumber{};
class InvalidArray{};

typedef enum _COLORS
{
	DARK_RED = RGB(255,128,128),
	DARK_GREEN = RGB(128,255,128),
	BROWN = RGB(192,192,128),
	DARK_BLUE = RGB(128,128,255),
	DARK_MAGENTA = RGB(192,128,192),
	DARK_CYAN = RGB(128,255,255),
	YELLOW = RGB(255,255,128),
	MAGENTA = RGB(255,128,255),
	WHITE = RGB(255,255,255)
} COLORS;

enum TYPE_OF_SIGNAL
{
	SIGNAL_WITH_SQUARE_BRACKETS,
	SIGNAL_WITH_TRIANGULAR_BRACKETS,
	SIGNAL_WITHOUT_BRACKETS,
	SINGLE_SIGNAL_FROM_SCRIPT,
	GROUP_OF_SIGNALS
};

enum TYPE_OF_RULE
{
	IN_RANGE,
	OUT_OF_RANGE,
	RULE_NOT_SET
};

struct HighlightingRule
{
	unsigned __int64 Min;
	unsigned __int64 Max;
	int TypeOfRule; // IN_RANGE, OUT_OF_RANGE, RULE_NOT_SET
	HighlightingRule(){ Min = -1; Max = -1; TypeOfRule = RULE_NOT_SET; };
};

typedef struct _LineMembers
{
	unsigned __int64 TimeMark;
	CString Name;
	CString Comment;
	long Type;
	long TimeType;
	_LineMembers(): Name(""), Type(-1), TimeType(-1), TimeMark(-1){};
	bool IsTimeMarkClosing();
} LineMembers;

struct Signal
{
	CString Name;	
	BYTE FirstStatus;
	CArray<unsigned __int64, unsigned __int64> Changes;
	CArray<CString,CString> Comments;
	long TimeType;
	long SignalType;

    Signal();
	Signal( const Signal &OldSignal );
	Signal( LineMembers &LineMembrs );
	~Signal();
	void operator =(Signal &OldSignal);
	void Copy( const Signal &OldSignal );
};

class ScenarioSignals  
{
friend class			mymessages;
friend class			graphdata;

protected:
	
	mymessages			*StatusList;
	ULONG				NumberOfSignals;
	CString                         *Name;
	CString                         *OriginalName;
	BOOL                            *SignalUsed;
	int								*Type;// GROUP or SINGLE
	int                             *SignalOrder;
	CPoint                          *SignalPos;
	int								*SignalYSize;
	CArray<int, int>			    **SignalsInGroup;
	BOOL                            *SignalMarked;
	long							*SignalBackgroundColor;
	HighlightingRule				*Rules;
	int								GraphDeltaY;
	int								GraphOffsetY;
	const static long				YSizeOfSignalDivider = 3;
	int								LastMarkedSignalNumber;
	BOOL							Exist;
//-----------------------------------------------------------------------------------------------

protected:
	void                            FreeSignalDataArrays();
public:
	CString				GetOriginalName		( int Index );
	BOOL				CheckIfSignalWasUsed(int signalnumber);
	void				SetSignalUsed		(int signalnumber);
	int					GetType				( int SignalNumber );
	void				SetType				( int SignalNumber, int Type);
	int					GetNumberOfSignals	();
	int					GetNumberOfShownSignals();
	CArray<int,int> *	GetSignalsInGroup	( int NumberOfSignal );
	int					GetSignalNumber		( CString	_name );
	CString				GetSignalName		( int Index );
	CString				GetSignalName		( CPoint	point ); 
	HighlightingRule	GetRule				( int NumberOfSignal );
	void				SetRulesForMarkedSignals( unsigned __int64 Min, unsigned __int64 Max, int TypeOfRule );
	void				DeleteRulesForMarkedSignals();
	BOOL				LoadSignalsFromScriptFile(CString file_name);
	bool				LoadSignalsFromArray( const CArray< Signal, Signal > &Signals );
	BOOL				SignalsExist		();
						ScenarioSignals		(mymessages	*_StatusList);
	virtual				~ScenarioSignals	();
	void				WriteToVectorFile	(FILE *pFile);
	void				AddNewDefaultSignal	( CString &NameOfSignal );
	int					GetSignalNumberInGroupFromGraphView( int CoordY );
	int					CheckIfHighOrLowLevelOfSignal( int CoordY );
public:
	int					GetSignalOrder			(CString _name);
    int					GetSignalOrder			(int SignalNumber );
	int					GetSignalNumber			(CPoint point);
	void				SetDefaults				(void);
	void				SetDefaultsForSingleSignal( int NumberOfSignal );
	int					GetButtonY				(CPoint mpoint);
	int					PushSignalInColumn		( int SourceSignalNumber, CPoint MousePoint );
	void				MoveSignalToPositionOfTargetSignal(int SourceSignalNumber, int TargetSignalNumber);
	int					PushSignalToEnd			(int signalnumber);
	void				ChangeSignalsPositions	( int FirstSignalNumber, int SecondSignalNumber );
	int					GetTotalSignalDelta		(void);
	int					GetOnlySignalTotalDelta	();
	int					GetSignalNumber			(int signalorder);
	int					GetSignalPos			(int signalnumber) const;
	int					GetSignalYSize			(int i) const;
	int					GetSignalPosByOrder		( int order );
	int					GetSignalEndPos			(int signalnumber);
	int					DeleteSignalFromGraph	(int signalnumber);
	int					RefreshSignalsStatus	(void);
	int					GetGraphDeltaY			(void);
	BOOL				IfShowSignal			(int signalnumber);
	BOOL				CheckIfSignalMarked		(int signalnum);
	//int					GetNumberOfMarkedSignals();
	void				RemoveMarkedSignals		(void);
	void				RemoveMarksFromSignals	();
	void				Serialize				(CArchive& ar);
	int					AddShowSignal			(CString name);
	int					AddShowSignal			( int SignalNumber );
	void				SetSignalBackgroundColor( COLORREF Color, int SignalPos );
	COLORREF			GetSignalBackgroundColor( int SignalPos );
	bool				AddNewGroupFromMarked	( CString &NameOfNewGroup );
	void				CopyArrays				( ScenarioSignals* OldValues );
	int					GetDistanceBetweenTwoLinesInGroup();
	int					GetSignalPositionNumberInGroupFromButtonView( int CoordY );
	int					GetSignalPositionNumberInGroupFromButtonView( int NumberOfSignal, int CursorYPosition );
	void				DeleteSignalFromScenarioSignals( int NumberOfSignal );
	int					MoveSignalsInGroup( int SignalNumber, int OldPositionNumberInGroup, CPoint CursorPosition );
	int					MoveSignalsInGroup( int SignalNumber, int OldPositionNumberInGroup, int NewPositionNumberInGroup );
	CPoint				GetPositionsOfSignalInGroup( ULONG SignalNumber, int SignalInGroupNumber );
	void				OnSortSelectedWavesByName();
	void				MarkAllSignalsBetween			( CPoint MousePoint );
	int					GetFirstMarkedSignal			();
	int					GetMinYMarkedSignal				();
	int					GetNextMarkedSignal				( int StartPositionOfSearch );
	int					GetMinPositionOfMarkedSignals	();
	bool				MoreThanOneMarked				();
	int					SetShowSignalsAtUngroup			(int i);
    void				GetSelectedWaves				( std::vector<int> &SelectedWaves );

private:
	bool				CheckSignalIndex				( int Index ) const{ return ((Index < NumberOfSignals) && (Index >= 0)); };
	int					GetSignalIndex					( CPoint point );
	void				FillListOfSignalNamesAndUpdateNumberOfSignals( CArray<CString,CString> *SignalNames, CString FileName );
	bool				SignalIsFound					( CArray<CString,CString> *SignalNames, CString OriginalName );
	bool				TryToCreateArraysOfSignalsData	();
	void				FillNames						( CArray<CString,CString> *SignalNames );
	void				FillFields						( const CArray<Signal, Signal> &Signals );
	void				SetDefaultsForSignal			( int NumberOfSignal );
	int					GetCurrentOrder					();
	void				AddSignalToArray				( CArray<int, int> *ChosenSignals, int numberofsignals );
	void				AddSignalIfAbsent				( CArray<int, int> *ChosenSignals, int NumberOfSignal );
	bool				IncludeMarkedSignalsIntoGroup	( int NumberOfSignal );
	int					GetSizeFromNumberOfSignals		( int NumberOfSignal);
	bool				TryForSimilarGroup				( int NumberOfSignal );
	bool				FindInArray						( int Element, CArray<int,int> *SignalsInGroup );
	CString				CreateNameFromIncludedSignals	( int NumberOfSignal );
	void				SortSelectedWavesByName			( std::vector<int> &SelectedWaves );
};





class StringToGroupsSequences  
{
friend class			mymessages;
public:
	int					LoadExpression				(CString expression);
						StringToGroupsSequences		();
	virtual				~StringToGroupsSequences	();
public:
	int					numberofgroups;
	int					numberofsequnces			[MAXIMUM_INGROUP];
	CString				groups						[MAXIMUM_INGROUP];
};


struct WaveSignalStatistics
{
	unsigned __int64 MaxTimeInLevel[2];
	unsigned __int64 MinTimeInLevel[2]; 
	unsigned __int64 SumOfTimesInLevel[2]; 
	unsigned __int64 NumberOfLevels[2];

	void UpdateWaveSignalStatistics( WaveSignalStatistics Statistics );
	void ConvertToMS( int TimeDivider );
	WaveSignalStatistics();
};

struct ResultWaveSignalStatistics
{
	unsigned __int64 MaxTimeInLevel[2];
	unsigned __int64 MinTimeInLevel[2]; 
	unsigned __int64 MeanTimeInLevel[2]; 
};

class wavesignal
{
public:
	// variables
protected:
	mymessages					*StatusList;
	CString						name;
	CArray <__int64,__int64>	changes;
	CArray <CString,CString>	Comments;
public:
	BYTE type; // W_CONST, W_CLK, W_PWM, W_PWM_FILE, W_GROUP

	//functions
public:
	virtual void ExportInfo();
	CString						GetName				();
	void						SetName				(CString _name);
	int							GetSignalType		();
	void						SetSignalType		( int NewType );
	virtual DWORD				WriteComponentToGraphData(	graphdata* graph, 
															unsigned __int64 startposition, 
															unsigned __int64 offset,
															unsigned __int64 delta,
															unsigned __int64 length,
															int TimeDivider,
															WORD signalID,
															HighlightingRule Rule);
								wavesignal			(mymessages	*_StatusList);
	virtual						~wavesignal			();
	void						MarkIncludedChanges	( Signal CurrentSignal, bool **MarksForSignals, int NumberOfSignal );
	virtual unsigned __int64	GetFirstTimingChangeAfterTime( unsigned __int64 TimeLimit );
	void						SetFirstTimingChange( unsigned __int64 NewValue);
};

class SimpleWavesignal : public wavesignal  
{
friend class					mymessages;
public:
	void						AddBit				(BYTE _value, unsigned __int64 newabsoluteoffset);
	void						ComputeSignalStatistics( __int64 TotalTime );
	void						ExportInfo			();
	void						GetAbsoluteChanges		( CArray<__int64,__int64> *Changes, unsigned __int64 length );
	BYTE						GetBit				();
	char						GetBitName			();
	__int64						GetInterval         ( __int64 Point, __int64 TimeTopLimit ,CString *outComment = NULL);  //return an interval between nearest left and right changes 
	int							GetNumberInFile		();
	WaveSignalStatistics		GetSignalStatistics ();
	int							uploadstring		(CString    command, CString OriginalLine);
	void						ResetProccess		();
	void						SetFirstValues		();
	void						SetNumberInFile		(int _number);
								SimpleWavesignal			( mymessages	*_StatusList );
								SimpleWavesignal			( mymessages	*_StatusList, const Signal &Sig );
	virtual						~SimpleWavesignal			();
	DWORD						WriteComponentToGraphData(	graphdata* graph, 
															unsigned __int64 startposition, 
															unsigned __int64 offset,
															unsigned __int64 delta,
															unsigned __int64 length,
															int TimeDivider,
															WORD signalID,
															HighlightingRule Rule);
protected:	
	char						GetPWMBitName			();
	char						GetCLKBitName			();
	BYTE						GetPWMBit				();
	BYTE						GetCLKBit				();
	
	
	DWORD						WriteConstToGraphData	(	graphdata* graph, 
															unsigned __int64 startposition, 
															unsigned __int64 offset,
															unsigned __int64 length,
															int TimeDivider,
															WORD signalID,
															HighlightingRule Rule);
	DWORD						WriteClkToGraphData		(	graphdata* graph, 
															unsigned __int64 startposition, 
															unsigned __int64 offset,
															unsigned __int64 length,
															int TimeDivider,
															WORD signalID,
															HighlightingRule Rule);
	DWORD						WritePWMToGraphData		(	graphdata* graph, 
															unsigned __int64 startposition, 
															unsigned __int64 offset,
															unsigned __int64 delta,
															unsigned __int64 length,
															int TimeDivider,
															WORD signalID,
															HighlightingRule Rule);
	//Variables
protected:
	BOOL						readingvalues;
	BYTE						firststatus;
	BYTE						lastbitvalue;
	DWORD						number_in_file;
	DWORD						ciclenumber;
	ULONG						cicleoffset;
	unsigned __int64			bitoffset;
	unsigned __int64			absoluteoffset;
	ULONG						deltaoffset;
	ULONG						numofdeltas;
	WaveSignalStatistics		SignalStatistics;
};

class simple_group;
class GroupOfWavesignals : public wavesignal
{
private:
	SimpleWavesignal **IncludedSignals;
	int NumberOfSignals;

public:
	
	GroupOfWavesignals( mymessages	*_StatusList );
	virtual	~GroupOfWavesignals();
	int GetNumberOfSignals();
	SimpleWavesignal* GetWavesignal( int Index );
	void FillDataOfWavesignalGroup( CString NameOfWavesignalsGroup, int SignalNumber, simple_group* ChosenGroup );
	DWORD WriteComponentToGraphData( graphdata* graph, 
									 unsigned __int64 startposition, 
									 unsigned __int64 offset,
									 unsigned __int64 delta,
									 unsigned __int64 length,	
									 int TimeDivider,
									 WORD signalID,
									 HighlightingRule Rule);
	virtual unsigned __int64 GetFirstTimingChangeAfterTime( unsigned __int64 Time );
private:
	void SetChangesFromIncludedSignals( __int64 length );
	void AddWavesignalsFromArray ( CArray<SimpleWavesignal*, SimpleWavesignal*> *Wavesignals );
	void CreateChangesFromArray( CArray<__int64,__int64> **Changes );
};

class group  
{
friend class				mymessages;
public:
	void					DefineGroup						();
	unsigned long			GetEndPositionInScriptFile		();
	unsigned long			GetStartPositionInScriptFile	();
	unsigned long			GetEndPositionInVectorFile		();
	unsigned long			GetStartPositionInVectorFile	();
	CString					GetComments						();
	CString					GetFileName						();
	CString					GetName							();
	CString					GetStatusLine					();
	BYTE					GetType							();
	BOOL					GetGroupStatus					();
							group							(mymessages	*_StatusList);
	virtual					~group							();
	void					SetEndPositionInScriptFile		(unsigned long num);
	void					SetStartPositionInScriptFile	(unsigned long num);
	void					SetEndPositionInVectorFile		(unsigned long num);
	void					SetStartPositionInVectorFile	(unsigned long num);
	void					SetType							(BYTE  TYPE);
	void					SetFileName						(CString _filename);
	void					SetComment						(CString _comment);
	void					SetName							(CString _name);
	void					UnDefineGroup					();
protected:
	mymessages				*StatusList;
	BOOL					group_is_defined;
	CString					filename;
	CString					comments;
	CString					name;
	BYTE					type;						// symple group SIMPLE,complex group COMPLEX,frame FRAME
	unsigned long			startpositioninvectorfile;	
	unsigned long			endpositioninvectorfile;
	unsigned long			startpositioninscriptfile;
	unsigned long			endpositioninscriptfile;
};



class simple_group : public group  
{
friend class				mymessages;
friend class				graphdata;
public:
	bool					AddSignal					(wavesignal* _signal);
	BYTE					ConvertCharToBit			(char _bit);
	int						CheckForVectorFile			(CString line);
	int						DistributeBitsToSignals		(CString _line);
	void					ExportInformation			();
	__int64					GetClock					();
	CString					GetStrClock					();
	int						PutBitInSignal				(int signalpos,BYTE _bit, __int64 absoluteoffset);
	int						ReadSignalsNameFromFile		(CString line);
	void					SetClockPeriod				( unsigned __int64 _clk);
							simple_group				(	mymessages	*_StatusList,
															ScenarioSignals*	gsignals
														);
	virtual					~simple_group				();
	__int64					WriteComponentToVectorFile	(FILE *pVfile,unsigned __int64 startposition);
	__int64					WriteComponentToGraphData	(	graphdata *graph,
															unsigned __int64 startposition,
															unsigned __int64 offset,
															unsigned __int64 delta,
															int TimeDivider
														);
	CString					OptimizeVectorFile			(	CString filename, 
															CString* paramname, 
															CString* paramarg, 
															int numofparam
														);
	int						FinilizeReadingSignals		(void);
	WaveSignalStatistics	GetSignalStatistics			( int SignalNumber );
	wavesignal*				GetPointerToWavesignalByIndex(int Index);
	void					ReallocateWaveSignals		();
	void					FillArrayOfWaveSignalsByNamesOfIncludedSignals	( CArray<SimpleWavesignal*, SimpleWavesignal*> *Signals, int NumberOfSignal );
	void					RefreshWavesignalsGroups	();
	void					ReturnFreeSpace				();
	void					CutFreeSpace				();
protected:
	void					SetSignalsReadFirstValue	();
	DWORD					GetAbsoluteOffset(CString time);

protected:
	unsigned __int64		CutOffSpace;
	unsigned __int64		clocks;
	BYTE					signalfromfilestart;
	BYTE					signalfromfileend;
	wavesignal*				*wavesignals;
	ULONG					NumberOfSignals;
	ScenarioSignals*		globalsignals;
	int						numberoffilevectors;
	block					mblock;
	from_file				mfrom_file;
	DWORD					clockoffset;
};




class complex_group : public group  
{
friend class				mymessages;
public:
	void					ClearAllComponent		();
	CString					GetComponentStatusLine	(int pos);
	int						GetComponentSequences	(int pos);
	CString					GetComponentName		(int pos);
	int						GetNumberOfComponents	();
	int						AddComponent			(CString _group,WORD _sequences);
							complex_group			(mymessages	*_StatusList);
	virtual					~complex_group			();
protected:
	WORD			numberofcomponents;
	WORD			numberofsequencespercomponent[MAXIMUM_INGROUP];
	CString			groups[MAXIMUM_INGROUP];
	
};





class frame : public group  
{
friend class				mymessages;
public:
	void					SetVTotal				(CString num);
	void					SetHTotal				(CString num);
	void					SetCompressor			(CString ver);
	void					SetNFS					(CString num);
	void					SetSubRes				(CString num);
	CString					GetVTotal				();
	CString					GetCompressor			();
	CString					GetVTotal_2				();
	CString					GetHTotal				();
	CString					GetNFS					();
	CString					GetSubRes				();
	void					ClearAllComponents		();
	CString					GetComponentStatusLine	(int pos);
	int						AddComponent			(CString _group,WORD _sequences);
	int						GetComponentSequences	(int pos);
	CString					GetComponentName		(int pos);
	int						GetNumberOfComponents	();
							frame					(mymessages	*_StatusList);
	virtual					~frame					();
protected:
	WORD					numberofcomponents;
	WORD					numberofsequencespercomponent[MAXIMUM_INGROUP];
	CString					groups[MAXIMUM_INGROUP];
	CString					htotal;
	CString					vtotal;
	CString					nfs;
	CString					subres;
	CString					compressor;
};


//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////// Every script file describes one scenario
//////////////////////////////////////////////////////////////////////////////////////////////////

class scenario  
{
friend	class		graphdata;
friend	class		mymessages;
friend  class		ZWaveeditorDoc;
friend	struct		Signal;
public:
	CString			GetFrameVTotal									(CString framename);
	CString			GetFrameVTotal_2								(CString framename);
	CString			GetFrameHTotal									(CString framename);
	CString			GetFrameNFS										(CString framename);
	CString			GetFrameSubRes									(CString framename);
	void			GetFrameFormatFromLine							(CString scriptline,CString *groupname,CString *comment,CString *htotal,CString *vtotal,CString *nfs,CString *subres,CString *compressor);
	BOOL			CheckIfSelectedFrame							(CTreeCtrl *_tree,HTREEITEM pos);
	BOOL			CheckIfSelectedGroup							(CTreeCtrl *_tree,HTREEITEM pos);
	BOOL			CheckIfSelectedScriptRoot						(HTREEITEM pos);
	BOOL			CheckIfSelectedTree								(HTREEITEM pos);
	int				CheckScriptDefinitions							();
	void			ClosedialogWritingVector						();
	int				ExportTree										(CTreeCtrl *_tree,DWORD treenum);
	int				GenerateVectorFileFromFrame						(CString	framename,FILE *pVfile);
	CString			GetFileNameOnly									();
	CString			GetFileName										();
	CString			GetLineNumber									();
	int				GetNumberOfGroupByName							(CString _name,BYTE TYPE,BOOL rewriting);
	__int64         GetDistanceAndCommentBetweenNearestChanges      ( CPoint point, CString& Comment );
	unsigned long	GetNumberOffClocksInGroup						(group *pGroup);
	BOOL			GetScenarioStatus								();
	int				LoadGlobalSignalList							(ScenarioSignals	*_signals);
	void			LoadGlobalSignalListFromScriptFile				(CString FileName);
	void			LoadGlobalSignalListFromArray					( const CArray< Signal, Signal > &Signals );
	bool			LoadSignalsFromArray							( const CArray< Signal, Signal > &Signals, unsigned __int64 TotalSize );
	long			LoadScriptFile									( CString file_name );
	int				OnEditscriptfile								(CString name		,mymessages *templist);
	int				InitGraphData									( graphdata *GraphData, int selected, unsigned __int64 offset,unsigned __int64 delta,int maxx);
	int				InitGraphData									( graphdata *GraphData, CString groupname, unsigned __int64 offset,unsigned __int64 delta,int windowmaxx);
	int				FirstInitGraphData								( graphdata *GraphData, CString GroupName, unsigned __int64 offset,unsigned __int64 delta, long WindowMaxX );
	int				SetGraphDataTotalSize							( graphdata *GraphData, CString GroupName );
	int				OnItemInfo										(CString item_name);
	int				OnSavealltovectorfile							(CString directory,mymessages* files);
	void			OpendialogWritingVector							();
	void			SetName											(CString param_name);
					scenario										( mymessages *_StatusList, CString FileName );
	virtual			~scenario										();
	long			UpDateAllFromFile								();
	void			UpDateScriptFileFromTempList					(mymessages	*_templist);
	void			UpDateScriptFromTempList						(mymessages	*_templist);
	CString			GetNameOnly										(void);
	HTREEITEM		InsertItem										(CTreeCtrl* _tree, CString sname, HTREEITEM parent, int _image, int _subimage);
	WaveSignalStatistics GetStatisticsOfWavesignalInShownGroup		( int SignalNumber );
	void			CreateGroupOfWavesignalsForEachSimpleGroupInScenario( CString NameOfGroup );
	void			CreateGroupOfWavesignalsForEachGroupInScenarioSignls();
	CString			GetSignalNameInGroupFromGraphView				( CPoint point );
	void			DeleteMarkedSignalsPermanently					();
	void			Ungroup											();
	CString			GetOriginalTimeType								();
	CString			GetCurrentTimeType								();
	void			ChangeTimeDivider								();
	__int64			ConvertTimeToOriginalType						( __int64 TimeValue );
	void			ExcludeChangesByString							( CArray< Signal, Signal > &Signals, long LineType );
	void			ExcludeUnusedStringsByWord						( CArray< Signal, Signal > &Signals, long LineType );
	void			ExcludeUnusedStringsByPreciseName				( CArray< Signal, Signal > &Signals, long LineType );
	void			CutReturnFreeSpace								();
	void			Serialize										( CArchive &ar );
	unsigned __int64 GetFirstTimingChangeAfterTime					(int GroupNum, int SignalNum, unsigned __int64 Time);
	unsigned __int64 GetFirstTimingChangeAfterTime					(int GroupNum, int SignalNum, unsigned __int64 Time, unsigned __int64& Disp);
	void			OnSortSelectedWavesByVal						( CString& GroupName );
	void			SortSelectedWavesByVal							( std::vector<int> &SelectedWaves, CString& GroupName );

protected:
	int				GetSignalFromGraphView							( CPoint point );
	int				AddFrameORGroupToTree							(CTreeCtrl *_item,HTREEITEM _parent,group* parentgroup);
	int				CheckIfGroupBegin								(CString _line);
	int				CheckIfGroupBegin2								(CString _line);
	int				CheckNumberOfLineInComponents					(group *wgroup);
	void			DeleteAll										();
	void			GetGroupFormatFromLine							(CString scriptline,CString *groupname,CString *comment,int *number, CString *TimeType );
	CString			rebuild_string_to_command						(CString _line);
	int				SubProccessInEditingScriptFile					(CString _line,CString groupcomment,int number,BYTE type);
	int				SubProccessInLoadingScriptFile					(CString _line,CString groupcomment,int number,BYTE type);
	unsigned __int64 WriteComponentToVectorFile					(FILE	*pVfile,group *wgroup,unsigned __int64 startposition);
	unsigned __int64 WriteComponentToGraphData						(group *wgroup,unsigned __int64 startposition,unsigned __int64 offset, unsigned __int64 delta,WORD deepness, graphdata *GraphData);
	WaveSignalStatistics GetStatisticsOfWavesignal					(group *wgroup, int SignalNumber);
	unsigned __int64 GetPositionOfFirstGroupAfterGlobalPosition		( group *wgroup, unsigned __int64 GlobalPosition, unsigned __int64 StartPosition );
	void			DeleteSignal									( int SignalNumber );

private:
	void CutFreeSpace();
	void ReturnFreeSpace();
	simple_group * GetFirstSimpleGroup();
	void MarkIncludedChanges( CArray< Signal, Signal > &Signals, bool **MarksForSignals, long LineType );
	void RemoveUnmarkedChanges( CArray< Signal, Signal > &Signals, bool **MarksForSignals, long LineType );
	void DeleteEmptySignals( CArray< Signal, Signal > &Signals );
	bool CreateFrameForScriptFromLog( unsigned __int64 TotalSize );
	bool CreateSimpleGroupForScriptFromLog( const CArray< Signal, Signal > &Signals, unsigned __int64 TotalSize );
	CString	CutUnUsedPartForScriptFile( CString OriginalName );
	BOOL CheckIfFullScriptPath( CString name );

protected:
	DWORD															LastTreeNumber;
	DWORD															TreeNumber;
	CString															HTotal;
	CString															VTotal;
	CString															NFS;
	CString															SubRes;
	CString															Compressor;
	unsigned long													endblockfileposition;
	unsigned long													startblockfileposition;
	unsigned long													offsetinfile;
//	BOOL															lockchanges;
	CArray	<HTREEITEM,HTREEITEM>									scenariotree;
	mymessages														*StatusList;
	mymessages														*templist;
//	for file reading / writing parameters --------------------------------------------------------------
	CString															filename;
	CStdioFile														scriptfile;
	CString															line;
	unsigned long													linenumber;
	LogReadingType													LogReadType;
//------------------------------------------------------------------------------------------------------
	unsigned __int64												numberofclocksingroup;
	group*															groups[MAXIMUM_GROUPS];
	WORD															numberofgroups;
	int																selectedgroup;
	CString															name;
	BOOL															scenariodefined;
	CString															OriginalTimeType;
	int																TimeDivider;
	bool															FreeSpaceCutOff;

public:
	graphdata														mygraphdata;
	ScenarioSignals													*globalsignals;
};

#endif // !defined(AFX_LANGUAGECOMPONENTS_H__A5613CDC_A001_4D02_8BA2_EFE6D50C0AFD__INCLUDED_)
